﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jbe.TestSuite.TestDevices.Interface;
using Jbe.TestSuite.TestDevices.FunctionGenerator.Driver;
using Jbe.TestSuite.Infrastructure.Interface;
using Jbe.TestSuite.TestDevices.FunctionGenerator.Interface;
using Jbe.Composite.Extensions;
using Jbe.TestSuite.TestDevices.FunctionGenerator.Driver.Domain;
using Jbe.TestSuite.TestDevices.FunctionGenerator.Driver.Properties;

namespace Jbe.TestSuite.TestDevices.FunctionGenerator.Driver.Applications
{
    internal class DeviceController : IDevice, IFunctionGeneratorProvider
    {
        private readonly ITestDeviceManager testDeviceManager;
        private readonly IFunctionGenerator functionGenerator;


        public event EventHandler Disconnected;


        public DeviceController(IApplicationContainer container, ITestDeviceManager testDeviceManager)
        {
            this.testDeviceManager = testDeviceManager;
            this.functionGenerator = container.Resolve<FunctionGeneratorDriver>();
        }


        public string ProfileName
        {
            get { return ProfileNames.FunctionGenerator; }
        }

        public string ProductName
        {
            get { return Resources.VirtualFunctionGenerator; }
        }

        public string Manufacturer
        {
            get { return Resources.Jbe; }
        }

        public IFunctionGenerator FunctionGenerator
        {
            get { return functionGenerator; }
        }


        public void Run()
        {
            testDeviceManager.Register(this);
        }

        public void Disconnect()
        {
            testDeviceManager.Deregister(this);
            OnDisconnected(EventArgs.Empty);
        }

        protected virtual void OnDisconnected(EventArgs e)
        {
            if (Disconnected != null) { Disconnected(this, e); }
        }
    }
}
